package com.jhd.fuzhou.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DeleteUnuseZero {
    /**
     * 去掉给定字符串（小数）后面的无效0
     *
     * @param value 小数的字符串表示
     * @return 如果转换失败，返回null
     */
    public static String convertByPattern(String value) {
        if(value==null){
            return null;
        }else{
            String regex = "^(-?\\d*)(\\.?0*)$";
            Matcher matcher = Pattern.compile(regex).matcher(value);
            if (matcher.find()) {
                return matcher.group(1);
            }
            String regex1 = "^(-?\\d*\\.\\d*[1-9])(0*)$";
            Matcher matcher1 = Pattern.compile(regex1).matcher(value);
            if (matcher1.find()) {
                return matcher1.group(1);
            }
        }
        return null;
    }
}
